﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;
using System.Collections;

namespace ATW.MT.BUS
{
    public class bus_D_SystemArgs
    {
        DataAccess da = null;
        public bus_D_SystemArgs()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 系统参数查询
        /// </summary>
        /// <returns></returns>
        public DataTable SysQuery()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select * from D_SystemArgs where rowstatus<>'2'");
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 获取参数值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string GetSysArgs(string key)
        {
            string sql = "select [value] from D_SystemArgs where rowstatus<>'2' and [key]='" + key + "'";
            object o = da.ExecuteScalar(sql.ToString());
            if (o != null && o.ToString() != "")
            {
                return o.ToString();
            }
            return "";
        }
        //获取更新语句
        public string GetUpdateString(string key, string value)
        {
            return "update D_SystemArgs set [value]='" + value + "' where [key]='" + key + "'";
        }
        /// <summary>
        /// 批量执行
        /// </summary>
        /// <param name="al"></param>
        /// <returns></returns>
        public bool ExAL(ArrayList al)
        {
            return da.ExecuteArrayList(al);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <returns></returns>
        public DataTable getUserList()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select [id],[value] from D_SystemArgs where [key]='DefaultMsgReceiver' and rowstatus='0'");
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <returns></returns>
        public int delUser(string id)
        {
            string sql = "update D_SystemArgs set rowstatus='2' where [id]='" + id + "'";
            return da.ExcuteNoQuery(sql);
        }
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        public int addUser(string mail)
        {
            string sql = "insert into D_SystemArgs([key],[value],[Desc])values('DefaultMsgReceiver','" + mail + "','默认推送给哪个后台人员')";
            return da.ExcuteNoQuery(sql);
        }
        #endregion
    }
}